package com.xgk.boot.module.core.controller.admin.payment;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xgk.boot.framework.common.core.KeyValue;
import com.xgk.boot.framework.common.pojo.CommonResult;
import com.xgk.boot.framework.common.pojo.PageResult;
import com.xgk.boot.framework.common.util.object.BeanUtils;
import com.xgk.boot.module.core.controller.admin.channel.vo.sp.*;
import com.xgk.boot.module.core.controller.admin.channel.vo.spapi.ApiPageRespVO;
import com.xgk.boot.module.core.controller.admin.payment.vo.credit.CreditPageReqVO;
import com.xgk.boot.module.core.controller.admin.payment.vo.credit.CreditPageRespVO;
import com.xgk.boot.module.core.controller.admin.payment.vo.credit.CreditSaveReqVO;
import com.xgk.boot.module.core.controller.admin.payment.vo.payment.PaymentPageRespVO;
import com.xgk.boot.module.core.dal.entity.channel.ApiServiceDO;
import com.xgk.boot.module.core.dal.entity.channel.ServiceProviderDO;
import com.xgk.boot.module.core.dal.iservice.PaymentRecordsService;
import com.xgk.boot.module.core.dal.iservice.ServiceProviderService;
import com.xgk.boot.module.core.dal.iservice.TemporaryCreditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

import static com.xgk.boot.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 授信")
@RestController
@RequestMapping("/admin/tempcredit")
@Validated
public class TemporaryCreditController {

    @Resource
    private TemporaryCreditService temporaryCreditService;

    @PostMapping("/create")
    @Operation(summary = "创建授信")
    public CommonResult<Long> createCredit(@Valid @RequestBody CreditSaveReqVO createReqVO) {
        return success(temporaryCreditService.createCredit(createReqVO));
    }

//    @PostMapping("/active")
//    @Operation(summary = "启用供应商")
//    public CommonResult<Boolean> activeCredit(@RequestParam Long asId, @RequestParam Integer asStatus) {
//        spService.activeCredit(asId, asStatus);
//        return success(true);
//    }


    @GetMapping("/page")
    @Operation(summary = "获得授信分页")
    public CommonResult<PageResult<CreditPageRespVO>> getCreditPage(CreditPageReqVO pageReqVO) {
        Page<CreditPageRespVO> pageResult = temporaryCreditService.getCreditPage(pageReqVO);
        PageResult<CreditPageRespVO> pr = new PageResult<>(pageResult.getRecords(), pageResult.getTotal());

        return success(pr);
    }

}
